package com.raising.modules.sys.controller;

import com.raising.ConstantParam;
import com.raising.framework.controller.BaseController;
import com.raising.framework.entity.ResultVo;
import com.raising.framework.interceptor.Page;
import com.raising.modules.sys.entity.Olog;
import com.raising.modules.sys.service.OlogService;
import com.raising.utils.JStringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 操作日志 控制器
 * @author gaoy
 * @createTime 2018-01-19 14:46:49
 */
@Controller
@RequestMapping("${adminPath}/sys/olog")
public class OlogController extends BaseController {

    @Autowired
    private OlogService ologService;

    /**
     * 跳转至列表页面
     * @author gaoy
     * @createTime 2018-01-19 14:46:49
     */
    @RequiresPermissions("sys:olog:view")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list() {
        olog("进入操作日志管理页面");
        return "sys/olog/list";
    }

    /**
     * 加载列表分页数据
     * @author gaoy
     * @createTime 2018-01-19 14:46:49
     */
    @RequiresPermissions("sys:olog:view")
    @RequestMapping(value = "/getPage.json", method = RequestMethod.POST)
    public @ResponseBody ResultVo getPage(Olog olog,Page<Olog> page,String showDate) throws Exception{
        if(showDate!=null && showDate.contains(ConstantParam.BOLANG)){
            String[] showDateAttr = showDate.split(ConstantParam.BOLANG);
            olog.setBeginDateStr(JStringUtils.trim(showDateAttr[0]));
            olog.setEndDateStr(JStringUtils.trim(showDateAttr[1]));
        }
        page.setEntity(olog);
        page.setOrderBy(" a.id desc ");
        return ResultVo.success().data(ologService.getPage(page));
    }

}
